package com.ruoyi.purchase.service.impl;

import com.ruoyi.purchase.domain.PurchaseTrace;
import com.ruoyi.purchase.mapper.PurchaseTraceMapper;
import com.ruoyi.purchase.service.IPurchaseTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * purchaseTraceService业务层处理
 * 
 * @author kevinness
 * @date 2025-01-31
 */
@Service
public class PurchaseTraceService implements IPurchaseTraceService
{
    @Autowired
    private PurchaseTraceMapper purchaseTraceMapper;

    /**
     * 查询purchaseTrace
     *
     * @param orderNo purchaseTrace主键
     * @return purchaseTrace
     */
    @Override
    public PurchaseTrace selectPurchaseTraceByOrderNo(String orderNo)
    {
        return purchaseTraceMapper.selectPurchaseTraceByOrderNo(orderNo);
    }

    /**
     * 查询purchaseTrace列表
     *
     * @param purchaseTrace purchaseTrace
     * @return purchaseTrace
     */
    @Override
    public List<PurchaseTrace> selectPurchaseTraceList(PurchaseTrace purchaseTrace)
    {
        return purchaseTraceMapper.selectPurchaseTraceList(purchaseTrace);
    }

    /**
     * 新增purchaseTrace
     *
     * @param purchaseTrace purchaseTrace
     * @return 结果
     */
    @Override
    public int insertPurchaseTrace(PurchaseTrace purchaseTrace)
    {
        return purchaseTraceMapper.insertPurchaseTrace(purchaseTrace);
    }

    /**
     * 修改purchaseTrace
     *
     * @param purchaseTrace purchaseTrace
     * @return 结果
     */
    @Override
    public int updatePurchaseTrace(PurchaseTrace purchaseTrace)
    {
        PurchaseTrace trace = purchaseTraceMapper.selectPurchaseTraceByOrderNo(purchaseTrace.getOrderNo());
        if(trace != null){
            return purchaseTraceMapper.updatePurchaseTrace(purchaseTrace);
        }
        else{
            return purchaseTraceMapper.insertPurchaseTrace(purchaseTrace);
        }
    }

    /**
     * 批量删除purchaseTrace
     *
     * @param orderNos 需要删除的purchaseTrace主键
     * @return 结果
     */
    @Override
    public int deletePurchaseTraceByOrderNos(String[] orderNos)
    {
        return purchaseTraceMapper.deletePurchaseTraceByOrderNos(orderNos);
    }

    /**
     * 删除purchaseTrace信息
     *
     * @param orderNo purchaseTrace主键
     * @return 结果
     */
    @Override
    public int deletePurchaseTraceByOrderNo(String orderNo)
    {
        return purchaseTraceMapper.deletePurchaseTraceByOrderNo(orderNo);
    }
}
